package org.rooster.genetic;

import org.rooster.manager.TaskManager;

/**
 * Created by IntelliJ IDEA.
 * User: manorama
 * Date: 6/4/12
 * Time: 9:12 AM
 * To change this template use File | Settings | File Templates.
 */
public class GeneIndex {

    /**
     * Returns the starting index for a specific task
     *
     * @param sectionNo
     * @return
     */
    public static int getSectionStart(int sectionNo) {
        int sectionStart = 0;
        for(int i=0; i<sectionNo; i++) {
            for(int j=0; j< TaskManager.NO_OF_TIME_SLOTS; j++) {
                sectionStart += TaskManager.getRequirement(i, j);
            }
        }
        return sectionStart;
    }

    /**
     * Returns the ending index for a specific task
     *
     * @param sectionNo
     * @return
     */
    public static int getSectionEnd(int sectionNo) {
        int sectionEnd = 0;
        for(int i=0; i<=sectionNo; i++) {
            for(int j=0; j< TaskManager.NO_OF_TIME_SLOTS; j++) {
                sectionEnd += TaskManager.getRequirement(i, j);
            }
        }
        return sectionEnd - 1;
    }

    /**
     * Returns the starting index of a specific time slot of a given task
     *
     * @param sectionNo
     * @param timeSlotNo
     * @return
     */
    public static int getTimeSlotStart(int sectionNo, int timeSlotNo) {
        int timeSlotStart = 0;
        timeSlotStart += getSectionStart(sectionNo);
        for(int i=0; i<timeSlotNo; i++) {
            timeSlotStart += TaskManager.getRequirement(sectionNo, i);
        }
        return timeSlotStart;
    }

    /**
     * Returns the end index of the specific time slot of a given task
     * @param sectionNo
     * @param timeSlotNo
     * @return
     */
    public static int getTimeSlotEnd(int sectionNo, int timeSlotNo) {
        int timeSlotEnd = 0;
        timeSlotEnd += getSectionStart(sectionNo);
        for(int i=0; i<=timeSlotNo; i++) {
            timeSlotEnd += TaskManager.getRequirement(sectionNo, i);
        }
        return timeSlotEnd-1;
    }

    /**
     * Returns the starting index of a specific resource type
     * for a given task and a time slot
     *
     * @param sectionNo
     * @param timeSlot
     * @param resourceType
     * @return
     */
    public static int getResourceTypeStart(int sectionNo, int timeSlot, int resourceType) {
        int resourceTypeStart = 0;
        resourceTypeStart += getTimeSlotStart(sectionNo, timeSlot);
        for(int i=0; i<resourceType; i++) {
            resourceTypeStart += TaskManager.getResourceTypeRequirement(sectionNo, timeSlot, i);
        }
        return resourceTypeStart;
    }

    /**
     * Returns the end index of a specific resource type
     * for a given task and a time slot
     * @param sectionNo
     * @param timeSlot
     * @param resourceType
     * @return
     */
    public static int getResourceTypeEnd(int sectionNo, int timeSlot, int resourceType) {
        int resourceTypeEnd = 0;
        resourceTypeEnd += getTimeSlotStart(sectionNo, timeSlot);
        for(int i=0; i<=resourceType; i++) {
            resourceTypeEnd += TaskManager.getResourceTypeRequirement(sectionNo,timeSlot, i);
        }
        return resourceTypeEnd-1;
    }
}
